package com.hibase.core.rule.web.rulemenu;


import com.hibase.common.entity.ResponseModel;
import com.hibase.common.util.EntityUtil;
import com.hibase.core.rule.constant.RuleType;
import com.hibase.core.rule.entity.rulemenu.RuleMenu;
import com.hibase.core.rule.entity.rulemenu.vo.RuleMenuInsertVO;
import com.hibase.core.rule.entity.rulemenu.vo.RuleMenuListVO;
import com.hibase.core.rule.entity.rulemenu.vo.RuleMenuUpdateVO;
import com.hibase.core.rule.entity.rulemenu.vo.RuleMenuViewVO;
import com.hibase.core.rule.service.rulemenu.RuleMenuService;
import com.hibase.core.web.annotation.HibasePostRequestMapping;
import com.hibase.core.web.entity.OperationIdEntity;
import com.hibase.core.web.entity.OperationIdNullEntity;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * <p>
 * 规则菜单表 前端控制器
 * </p>
 *
 * @author hufeng
 * @since 2019-06-10
 */
@RestController
@RequestMapping("/rule-menu")
@Api(tags = "规则菜单表")
public class RuleMenuController{

    @Autowired
    private RuleMenuService ruleMenuService;

    @ApiOperation(value = "查询规则菜单表列表(带层级，查询第一级传空)", httpMethod = "POST")
    @HibasePostRequestMapping(value = "selectRuleMenuList")
    public ResponseModel<List<RuleMenuListVO>> selectRuleMenuList(@RequestBody OperationIdNullEntity idEntity) {

        return ResponseModel.successMsg(ruleMenuService.selectRuleMenuList(idEntity.getId()));
    }

    @ApiOperation(value = "新增规则菜单表记录（新增菜单）", httpMethod = "POST")
    @HibasePostRequestMapping(value = "insertRuleMenu")
    public ResponseModel<String> insertRuleMenu(@RequestBody RuleMenuInsertVO insertVO) {

        RuleMenu entity = EntityUtil.transform(insertVO, RuleMenu.class);

        ruleMenuService.saveRuleMenu(entity);

        return ResponseModel.successMsg(entity.getId());
    }

    @ApiOperation(value = "修改规则菜单表记录", httpMethod = "POST")
    @HibasePostRequestMapping(value = "updateRuleMenu")
    public ResponseModel<String> updateRuleMenu(@RequestBody RuleMenuUpdateVO updateVO) {

        RuleMenu entity = EntityUtil.transform(updateVO, RuleMenu.class);

        ruleMenuService.saveRuleMenu(entity);

        return ResponseModel.successMsg(entity.getId());
    }

    @ApiOperation(value = "查询规则菜单表详情", httpMethod = "POST")
    @HibasePostRequestMapping(value = "viewRuleMenuDetails")
    public ResponseModel<RuleMenuViewVO> viewRuleMenuDetails(@RequestBody OperationIdEntity operationidEntity) {

        RuleMenuViewVO ruleMenuViewVO = EntityUtil.transform(ruleMenuService.viewRuleMenu(operationidEntity.getId()), RuleMenuViewVO.class);

        ruleMenuViewVO.setType(RuleType.RULE_TYPE_MENU.getName());

        return ResponseModel.successMsg(ruleMenuViewVO);
    }

    @ApiOperation(value = "删除规则菜单表记录", httpMethod = "POST")
    @HibasePostRequestMapping(value = "/deleteRuleMenu")
    public ResponseModel<String> deleteRuleMenu(@RequestBody OperationIdEntity delete) {

        ruleMenuService.deleteRuleMenu(delete.getId());

        return ResponseModel.successMsg();
    }
}
